#include"process.h"

const char rotate[]={"|/-\\"};

void process3(double rate)
{
    static int rotate_cnt = 0;
    static char arr[SIZE] = {0};
    int len = strlen(rotate);

    rotate_cnt = ++rotate_cnt % len;

    if(rate < MAX_RATE && rate > 0)
    {
        arr[(int)rate-1]=STYLE_BODY; 
        arr[(int)rate]=STYLE_HEAD; 
    }   
    else if(rate == MAX_RATE)
    {
        arr[(int)rate]='\0'; 
        arr[(int)rate-1]=STYLE_BODY;
    }
    printf("[%-100s][%6.2lf%%][%c]\r",arr,rate,rotate[rotate_cnt%len]);
    fflush(stdout);
}

void process2(int rate)
{
    static char arr[SIZE] = {0};
    int len = strlen(rotate);
    if(rate <= MAX_RATE && rate >= 0)
    {
        printf("[%-100s][%3d%%][%c]\r",arr,rate,rotate[rate%len]);

        fflush(stdout);

        arr[rate]=STYLE; 
    }   
}



void process1()
{
    char arr[SIZE] = {0};
    int rate = 0;
    int len = strlen(rotate);
    while(rate <= MAX_RATE)
    {
        printf("[%-100s][%3d%%][%c]\r",arr,rate,rotate[rate%len]);
        usleep(STIME);
        arr[rate++]=STYLE; 
    }

    printf("\n");
}
